package com.enqualcomm.kids.mvp.voiceschedule;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.enqualcomm.kids.R;
import com.enqualcomm.kids.bean.VoiceSchedule;

import java.util.List;

/**
 * Created by yinzhiqun on 2016/3/11.
 */
public class VoiceScheduleAdapter extends RecyclerView.Adapter<VoiceScheduleAdapter.ViewHolder> {
    List<VoiceSchedule> voiceSchedules;
    LayoutInflater inflater;

    public VoiceScheduleAdapter(List<VoiceSchedule> voiceSchedules, LayoutInflater inflater) {
        this.voiceSchedules = voiceSchedules;
        this.inflater = inflater;
    }

    public void changeData(List<VoiceSchedule> voiceSchedules) {
        this.voiceSchedules = voiceSchedules;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_voice_schedule, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final VoiceSchedule voiceSchedule = voiceSchedules.get(position);
        holder.contentTv.setText(voiceSchedule.content);
        holder.datetimeTv.setText(voiceSchedule.datetime);

//        Calendar calendar = Calendar.getInstance();
//        int year = calendar.get(Calendar.YEAR);
//        int month = calendar.get(Calendar.MONTH)+1;
//        int day = calendar.get(Calendar.DAY_OF_MONTH);
//        int hour = calendar.get(Calendar.HOUR);
//        int minute = calendar.get(Calendar.MINUTE);
//        long timeNumber = year*100000000L + month*1000000 + day*10000 + hour*100 + minute;
//
//        String s = voiceSchedule.datetime.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", "");
//        MyLogger.jLog().i(timeNumber);
//        MyLogger.jLog().i(s);
//        if (Long.parseLong(s)>timeNumber){//还没有过期
//            holder.contentTv.setTextColor(Color.rgb(0x33, 0x33, 0x33));
//        }else{//已经过期
//            holder.contentTv.setTextColor(Color.rgb(0x99, 0x99, 0x99));
//        }
    }

    @Override
    public int getItemCount() {
        return voiceSchedules==null?0:voiceSchedules.size();
    }

    public String getId(int position){
        return voiceSchedules.get(position).id;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView contentTv;
        public TextView datetimeTv;

        public ViewHolder(View itemView) {
            super(itemView);
            this.contentTv = (TextView) itemView.findViewById(R.id.content_tv);
            this.datetimeTv = (TextView) itemView.findViewById(R.id.date_time_tv);
        }
    }
}
